package com.sw.zk.db;

import com.alibaba.druid.pool.DruidDataSource;
import com.sw.zk.zk.DbZkData;
import com.sw.zk.zk.ZKServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class DBConfig {
    /**
     * 初始化数据源
     * @return
     */
    @Bean
    public DataSource dataSource(@Autowired ZKServerConfig zkServerConfig) {
        DruidDataSource datasource = new DruidDataSource();
        DbZkData dbZkData = zkServerConfig.getDbZkData();

        datasource.setUrl(dbZkData.getUrl());
        datasource.setUsername(dbZkData.getUsername());
        datasource.setPassword(dbZkData.getPassword());
        datasource.setDriverClassName(dbZkData.getDriver());
       return datasource;
    }
}
